package homework_java.RoomQ.xy_java.src.Test;

import java.util.HashSet;
import java.util.Set;

public class StudentManager {
    Set<Student> stulist = new HashSet<>();
    int x=0;

    void addStudent(String sname,int sno,String smajor){

        if(x==0){
            stulist.add(new Student(sname, sno, smajor));
            System.out.println("添加成功");
            x+=1;
        }
        else{
            for(Student stu:stulist){
                if(stu.sname.equals(sname)&&stu.sno == sno&&stu.smajor.equals(smajor)){
                    System.out.println("该学生已经添加");
                    break;
                }
                else{
                    stulist.add(new Student(sname, sno, smajor));
                    System.out.println("添加成功");
                    break;
                }
            }
        }

    }

    void removeStudent(int sno) {
        boolean flag1 = true;
        while (flag1) {
            boolean flag2 = true;
            for (Student stu : stulist) {
                if (stu.sno == sno) {
                    stulist.remove(stu);
                    flag1=true;
                    flag2 = false;
                    break;
                }
            }
            if (flag2) {
                //System.out.println("没有此学生");
                flag1=false;
            }
        }
    }
}
